{
 "metadata": {
  "name": "",
  "signature": "sha256:3e37a6f0fa049a1bf1d2ccd37444625ffbff77f4fa446d5fb66246f4133b3ada"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import numpy as np\n",
      "import numpy.matrixlib as nm\n",
      "\n",
      "npa = np.array\n",
      "nmm = np.matrix\n",
      "def nmv(v):\n",
      "    if isinstance(v, (nm.defmatrix.matrix, np.ndarray)):\n",
      "        return v\n",
      "    else:\n",
      "        return nmm(v).T"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 1
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "Q = nmm([[1, 2], [3, 4]])\n",
      "b = nmv([5, 6])"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 2
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "x = nmv([7, 8])\n",
      "print .5 * x.T * Q * x + b.T * x"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "[[ 375.5]]\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "np.isclose([1., 1.], 1.)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 4,
       "text": [
        "array([ True,  True], dtype=bool)"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "def op(a, b):\n",
      "    return a + b\n",
      "seqs = [\n",
      "#     [],\n",
      "    [1],\n",
      "    [1, 2],\n",
      "    [1, 2, 3]\n",
      "]\n",
      "for seq in seqs:\n",
      "    print reduce(op, seq)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "1\n",
        "3\n",
        "6\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}